﻿
@{
    ViewBag.Title = "RoleList";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<section class="content-header">
    <h1>
        角色管理
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active">角色管理</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                    <button type="button" class="btn btn-success btn-sm" id="btnAdd">添加角色</button>
                    <h3 class="box-title"></h3>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover body-table-head">
                        <thead>
                            <tr>
                                <th>
                                    ID
                                </th>
                                <th>
                                    角色名称
                                </th>
                                <th>
                                    所属类别
                                </th>
                                <th>
                                    创建时间
                                </th>
                                <th class="t_c">
                                    操作
                                </th>
                            </tr>
                        </thead>
                        <tbody id="tbodylist"></tbody>
                    </table>
                    <div class="no-data" id="nodata" style="display:none;">
                        <div class="img-box"></div>
                        <div class="text">暂无数据</div>
                    </div>
                </div>
                <div class="box-footer clearfix ">
                    <ul id="pagination" class="pagination pagination-sm no-margin pull-right"></ul>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>

    </div>
</section>
@section scriptsBottom{
    <script src="@Url.Content("~/lib/art-template/template-web.js")"></script>
    <script id="dataItemTpl" type="text/html">
        {{each data}}
        <tr>
            <td>
                {{$value.RoleID}}
            </td>
            <td>
                {{$value.RoleName}}
            </td>
            <td>
                {{$value.TypeName}}
            </td>
            <td>
                {{$value.CreatedTime}}
            </td>
            <td class="t_c">
                <button type="button" class="btn btn-info btn-xs" onclick="edit('','{{$value.RoleID}}')">编辑</button>
                <button type="button" class="btn btn-warning btn-xs" onclick="config('{{$value.RoleID}}')">配置权限</button>
                <button type="button" class="btn btn-danger btn-xs" onclick="del('{{$value.RoleID}}')">删除</button>
            </td>
        </tr>
        {{/each}}
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            search();
            $("#btnAdd").click(function () {
                edit('添加角色');
            });
        });

        //页码
        var pageIndex = 1;
        //查询
        function search() {
            var url = '@Url.Action("GetRoleList", "Authority")'
            //查询列表
            $.ajax({
                url: url,
                type: 'GET',
                dataType: "json",
                data: {
                    rows: 10,
                    page: pageIndex
                },
                success: function (data) {
                    if (data.data.length < 1) {
                        $("#nodata").show();
                        document.getElementById('tbodylist').innerHTML = "";
                        return;
                    }
                    $("#nodata").hide();
                    //模板渲染
                    var data = data;
                    var html = template('dataItemTpl', data);
                    document.getElementById('tbodylist').innerHTML = html;
                    //分页显示
                    $('#pagination').twbsPagination("destroy");
                    $('#pagination').twbsPagination({
                        totalItems: data.total,
                        visiblePages: 10,
                        pageSize: 10,
                        startPage: parseInt(pageIndex),
                        onPageClick: function (event, page) {
                            pageIndex = page;
                            search();
                        }
                    });
                }
            });
        }

        //修改
        function edit(title, id) {
            var tl = '修改角色';
            if (title != '') {
                tl = title;
            }
            var url = '@Url.Action("RoleEdit", "Authority")'
            if (id != null) {
                url += "?id=" + id;
            }
            BMCW.showTopLayer(tl, url, 630, 338);
        }

        //删除
        function del(id) {
            var url = '@Url.Action("DelRole", "Authority")'
            BMCW.DataConfirm("", function () {
                BMCW.ajax({
                    url: url,
                    type: "POST",
                    data: {
                        id: id
                    },
                    success: function (o) {
                        if (o.status == 0) {
                            BMCW.msg("删除成功", function () {
                                search();
                            });

                        } else {
                            BMCW.alert("删除失败");
                        }
                    }
                });
            })
        }

        function config(rid) {
            var url = '@Url.Action("RoleMenuRelaEdit", "Authority")?roleid=' + rid;
            BMCW.showTopLayer('配置权限', url, 800, 600);
        }

    </script>
}

